package com.traveldream.entities;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;


/**
 * The persistent class for the flight database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name="Flight.findAll", query="SELECT f FROM Flight f"),
	@NamedQuery(name="Flight.findByDeparturePlace",query="SELECT f FROM Flight f WHERE f.place.name LIKE :placeName"),
	@NamedQuery(name="Flight.findByArrivalPlace",query="SELECT f FROM Flight f WHERE f.product.place.name LIKE :placeName"),
	@NamedQuery(name="Flight.findBeetwenDates",query="SELECT f FROM Flight f WHERE (f.departureDate > :start AND f.arrivalDate < :end)"),
	@NamedQuery(name="Flight.findByStartingDate",query="SELECT f FROM Flight f WHERE f.departureDate > :start"),
	@NamedQuery(name="Flight.findByEndingDate",query="SELECT f FROM Flight f WHERE f.arrivalDate < :end"),
	@NamedQuery(name="Flight.findBeetwenDatesByPlace",query="SELECT f FROM Flight f WHERE (f.departureDate > :start AND f.arrivalDate < :end) AND f.product.place.name LIKE :placeName ")
})

public class Flight implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="product_id",insertable=false,updatable=false)
	private int productId;

	@Temporal(TemporalType.DATE)
	@Column(name="arrival_date")
	private Date arrivalDate;

	private String company;

	@Temporal(TemporalType.DATE)
	@Column(name="departure_date")
	private Date departureDate;

	//bi-directional many-to-one association to Place
	@ManyToOne
	@JoinColumn(name="departure_place_name")
	private Place place;

	//bi-directional one-to-one association to Product
	@OneToOne
	private Product product;

	public Flight() {
	}

	public int getProductId() {
		return this.productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	public Date getArrivalDate() {
		return this.arrivalDate;
	}

	public void setArrivalDate(Date arrivalDate) {
		this.arrivalDate = arrivalDate;
	}

	public String getCompany() {
		return this.company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public Date getDepartureDate() {
		return this.departureDate;
	}

	public void setDepartureDate(Date departureDate) {
		this.departureDate = departureDate;
	}

	public Place getPlace() {
		return this.place;
	}

	public void setPlace(Place place) {
		this.place = place;
	}

	public Product getProduct() {
		return this.product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
	
	@Override
	public boolean equals(Object obj) {
	    if(this.productId == ((Flight) obj).productId) {
	        return true;
	    }else {
	        return false;
	    }
	}

}